//处理路由记录的前置导航代码
import router from './router'
import Store from './store'
router.beforeEach((to, from, next) => {
    // console.log(to.meta)
    if(to.meta.name == '登录'){  //这一步是去除top.vue里的登录导航记录
      next()
      return
    }
    let key = to.meta
  
    let index = stopAdd(key)
  
    if (index == -1) {
      key.show = true
      Store.commit('addRouter', key)
    } else {
      Store.commit('changeStyle', key)
    }
  
    next()
  })
  
  
  function stopAdd(key) {
    let routerDatas = Store.state.routerData
    let index = routerDatas.findIndex((item) => {
      return item.name == key.name
    })
    return index
  }